package com.sdcqjy.property.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.sdcqjy.mylibrary.OtherUtils;
import com.sdcqjy.mylibrary.widget.SpacesItemDecoration;

/**
 * Created by 磁磁帅 on 2018/3/31.
 * 功能：
 */

public class WItemDecoration extends SpacesItemDecoration {
    public WItemDecoration(Context context, float dpValue) {
        super(OtherUtils.dip2px(context, dpValue), new boolean[]{false, false, false, true});
        paint = new Paint();
        paint.setColor(0xFFffFFff);
        paint.setStyle(Paint.Style.FILL_AND_STROKE);
    }

    private Paint paint;

    public WItemDecoration setColor(int color) {
        paint.setColor(color);
        return this;
    }

    public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
        int childCount = parent.getChildCount();
        int left = parent.getPaddingLeft();
        int right = parent.getWidth() - parent.getPaddingRight();
        for (int i = 0; i < childCount ; i++) {
            View view = parent.getChildAt(i);
            float top = view.getBottom();
            float bottom = view.getBottom() + space;
            c.drawRect(left, top, right, bottom, paint);
        }
    }
}